<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {

	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->model('user_model');

    } 
    
    
	public function index()
	{
	    $this->form_validation->set_rules('email','password','password2','firstname','lastname','required');
        $this->form_validation->set_error_delimiters('<span class="form-msg-error">', '</span>');
        $layout = array();
        if($this->form_validation->run())
    	{
    	    $email = $this->input->post('email', TRUE);
            $password = $this->input->post('password', TRUE);
            $password2 = $this->input->post('password2', TRUE);
            $firstname = $this->input->post('firstname', TRUE);
            $lastname = $this->input->post('lastname', TRUE);
            $address = $this->input->post('address', TRUE);
            $user_id = $this->user_model->create($email, $password, $firstname , $lastname ,$address);
            if($user_id){
                redirect('');
            }else{
                $layout["error"]= "email already exist.";
            }
	    }
	    
	    $layout = $this->load->view('register/index',$layout,TRUE);
		$this->load->view('layout/template' , array("content" => $layout) );
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */